<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@include file="../common/head.jsp"%>
<script language="JavaScript" src="js/jquery-1.8.3.min.js"></script>
<script>
    function showUser(userId){
        $.getJSON("user/showUser",{userId:userId},function(user){
            $("#userUl").append("<li>编号："+user.userId+"</li>");
            $("#userUl").append("<li>用户姓名："+user.userName+"</li>");
            $("#userUl").append("<li>生日："+user.birthday+"</li>");
        });
    }
    function showRoleUsers(roleId){
        if(roleId==0){
            alert("请选择角色");
            return;
        }
        $("#selectUser").empty();
        $.getJSON("user/showUsersByRoleId",{roleId:roleId},function(userList){
            for(var i=0;i<userList.length;i++) {
                $("#selectUser").append("<option value=\""+userList[i].userId+"\">"+userList[i].userName+"</option>");
            }
        });
    }
    function showUserAddress(userId){
        if(userId==0){
            alert("请选择用户");
            return;
        }
        $("#selectAddress").empty();
        $.getJSON("user/showAddressByUserId",{userId:userId},function(addressList){
            for(var i=0;i<addressList.length;i++){
                $("#selectAddress").append("<option value=\""+addressList[i].addressId+"\">"+addressList[i].addressDesc+"</option>");
            }
        });
    }
</script>
<div class="right">
    <div class="location">
        <strong>你现在所在的位置是:</strong>
        <span>用户管理页面</span>
    </div>
    <div class="search">
        <form method="post" action="user/showList">
            <span>用户姓名：</span>
            <input name="userName" class="input-text"	type="text" value="${param['userName'] }">

            <span>用户角色：</span>
            <select name="role.roleId" onchange="showRoleUsers(this.value)">
                <c:if test="${requestScope.roleList != null }">
                    <option value="0">--请选择--</option>
                    <c:forEach var="role" items="${requestScope.roleList}">
                        <option <c:if test="${role.roleId == param['role.roleId'] }">selected="selected"</c:if>
                                value="${role.roleId}">${role.roleName}</option>
                    </c:forEach>
                </c:if>
            </select>

            <input type="hidden" name="pageIndex" value="1"/>
            <input	value="查 询" type="submit" id="searchbutton">
    <c:if test="${sessionScope.user.role.roleId==1}">
            <a href="user/toAdd" >添加用户</a>
    </c:if>
        </form>
    </div>
    <!--用户-->
    <table class="providerTable" cellpadding="0" cellspacing="0">
        <tr class="firstTr">
            <th width="10%">用户编码</th>
            <th width="20%">用户姓名</th>
            <th width="10%">性别</th>
            <th width="10%">年龄</th>
            <th width="10%">电话</th>
            <th width="10%">图片</th>
            <th width="10%">用户角色</th>
            <th width="30%">操作</th>
        </tr>
        <c:forEach var="user" items="${requestScope.pageInfo.list }" varStatus="status">
            <tr>
                <td>
                    <span>${user.userCode }</span>
                </td>
                <td>
                    <span>${user.userName }</span>
                </td>
                <td>
							<span>
								<c:if test="${user.gender==1}">男</c:if>
								<c:if test="${user.gender==2}">女</c:if>
							</span>
                </td>
                <td>
                    <span>${user.userAge}</span>
                </td>
                <td>
                    <span>${user.phone}</span>
                </td>
                <td>
                    <span>
                        <c:set var="pics" value="${fn:split(user.userPicName,',')}"/>
                        <c:forEach items="${pics}" var="pic">
                            <img src="userPic/${pic}" alt="暂无" height="50"/>
                        </c:forEach>
                    </span>
                </td>
                <td>
                    <span>${user.role.roleName}</span>
                </td>
                <td>
                    <span><a class="viewUser" href="javascript:showUser(${user.userId})"><img src="images/read.png" alt="查看" title="查看"/></a></span>
                    <span><a class="viewUser" href="user/showUserById/${user.userId}"><img src="images/read.png" alt="查看" title="查看"/></a></span>
                    <c:if test="${sessionScope.user.role.roleId==1}">
                    <span><a class="modifyUser" href="UserModifyToServlet.action?userId=${user.userId}"><img src="images/xiugai.png" alt="修改" title="修改"/></a></span>
                    <span><a class="deleteUser" href="javascript:;" userid=${user.userId } username=${user.userName }><img src="images/schu.png" alt="删除" title="删除"/></a></span>
                    </c:if>
                </td>
            </tr>
        </c:forEach>
    </table>
<%--    <input type="hidden" id="totalPageCount" value="${totalPageCount}"/>--%>
    <c:import url="../common/rollpage.jsp">
        <c:param name="totalCount" value="${requestScope.pageInfo.total}"/>
        <c:param name="currentPageNo" value="${requestScope.pageInfo.pageNum}"/>
        <c:param name="totalPageCount" value="${requestScope.pageInfo.pages}"/>
    </c:import>
    <ul id="userUl"></ul>
    <ul>
        <li>
            用户列表：<select id="selectUser" onchange="showUserAddress(this.value)">
            <option value="0">请先选择角色</option>
        </select>
            地址列表：<select id="selectAddress">
            <option value="0">请先选择用户</option>
        </select>
        </li>
    </ul>
</div>
</section>

<!--点击删除按钮后弹出的页面-->
<div class="zhezhao"></div>
<div class="remove" id="removeUse">
    <div class="removerChid">
        <h2>提示</h2>
        <div class="removeMain">
            <p>你确定要删除该用户吗？</p>
            <a href="#" id="yes">确定</a>
            <a href="#" id="no">取消</a>
        </div>
    </div>
</div>

<%@include file="../common/foot.jsp" %>
